home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / misc / maplay1_2.lha / maplay / obuffer.h < prev    next >
C/C++ Source or Header  |  1995-02-19  |  5KB  |  195 lines

  1. /*
  2.  *  @(#) obuffer.h 1.8, last edit: 6/15/94 16:51:56
  3.  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
  4.  *  @(#) Berlin University of Technology
  5.  *
  6.  *  Idea and first implementation for u-law output with fast downsampling by
  7.  *  Jim Boucher (jboucher@flash.bu.edu)
  8.  *
  9.  *  LinuxObuffer class written by
  10.  *  Louis P. Kruger (lpkruger@phoenix.princeton.edu)
  11.  *
  12.  *  IffObuffer class written by
  13.  *  Erik Johannessen (erik2@afrodite.kih.no)
  14.  *
  15.  *  This program is free software; you can redistribute it and/or modify
  16.  *  it under the terms of the GNU General Public License as published by
  17.  *  the Free Software Foundation; either version 2 of the License, or
  18.  *  (at your option) any later version.
  19.  *
  20.  *  This program is distributed in the hope that it will be useful,
  21.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.  *  GNU General Public License for more details.
  24.  *
  25.  *  You should have received a copy of the GNU General Public License
  26.  *  along with this program; if not, write to the Free Software
  27.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28.  */
  29.  
  30. /*
  31.  * 19. Feb. 1995 IffObuffer class added by Erik Johannessen
  32.  *
  33. */
  34.  
  35. #ifndef OBUFFER_H
  36. #define OBUFFER_H
  37.  
  38. #include <iostream.h>
  39. #include <unistd.h>
  40. #include <stdlib.h>
  41. #include "all.h"
  42. #include "header.h"
  43. extern "C" {
  44. #include "audio_includes.h"
  45. }
  46.  
  47. static const uint32 OBUFFERSIZE = 2 * 1152;    // max. 2 * 1152 samples per frame
  48. static const uint32 MAXCHANNELS = 2;        // max. number of channels
  49.  
  50.  
  51. // Abstract base class for audio output classes:
  52. class Obuffer
  53. {
  54. public:
  55.   virtual     ~Obuffer (void) {}        // dummy
  56.   virtual void append (uint32 channel, int16 value) = 0;
  57.            // this function takes a 16 Bit PCM sample
  58.   virtual void write_buffer (int fd) = 0;
  59.            // this function should write the samples to the filedescriptor
  60.            // or directly to the audio hardware
  61. };
  62.  
  63.  
  64. // An audio output class for raw pcm output
  65. // or if ULAW is defined:
  66. // An audio output class for 8-bit ulaw output at 8 kHz:
  67. class FileObuffer : public Obuffer
  68. {
  69. private:
  70. #ifdef ULAW
  71.   ulawsample buffer[OBUFFERSIZE];
  72.   ulawsample *bufferp[MAXCHANNELS];
  73. #else
  74.   int16 buffer[OBUFFERSIZE];
  75.   int16 *bufferp[MAXCHANNELS];
  76. #endif
  77.   uint32 channels;
  78.  
  79. public:
  80.     FileObuffer (uint32 number_of_channels);
  81.        ~FileObuffer (void) {}
  82.   void    append (uint32 channel, int16 value);
  83.   void    write_buffer (int fd);
  84. };
  85.  
  86. #ifdef Iff
  87. #include <stdio.h>
  88. class IffObuffer : public Obuffer
  89. {
  90. private:
  91.     char buffer[OBUFFERSIZE];
  92.     char *bufferp[MAXCHANNELS];
  93.     unsigned int totbytes;
  94.     FILE *fout;
  95.     FILE *fout2;
  96.     uint32 channels;
  97.     char fname2[128];
  98.  
  99. public:
  100.     IffObuffer(uint32 number_of_channels,Header *,char *);
  101.     ~IffObuffer(void);
  102.     void append(uint32 channel,int16 value);
  103.     void write_buffer(int dummy);
  104. };
  105. #endif // Iff
  106.  
  107.  
  108. #ifdef Indigo
  109. // a class for direct sound output on SGI machines:
  110. class IndigoObuffer : public Obuffer
  111. {
  112. private:
  113.   int16 buffer[OBUFFERSIZE];
  114.   int16 *bufferp[MAXCHANNELS];
  115.   uint32 channels;
  116.   ALport port;
  117.  
  118. public:
  119.     IndigoObuffer (uint32 number_of_channels, Header *);
  120.        ~IndigoObuffer (void);
  121.   void    append (uint32 channel, int16 value);
  122.   void    write_buffer (int dummy);
  123. };
  124. #endif    // Indigo
  125.  
  126.  
  127. #ifdef SPARC
  128. // a class for direct sound output on SPARC 10 machines (dbri device)
  129. // or if ULAW is defined:
  130. // a class for direct sound output on SPARCs using a 8 kHz
  131. // 8-bit u-law audio device: (audioamd)
  132. class SparcObuffer : public Obuffer
  133. {
  134. private:
  135. #ifdef ULAW
  136.   ulawsample buffer[OBUFFERSIZE >> 1];        // mono only
  137.   ulawsample *bufferp;
  138. #else
  139.   int16 buffer[OBUFFERSIZE];
  140.   int16 *bufferp[MAXCHANNELS];
  141.   uint32 channels;
  142. #endif
  143.   static int audio_fd;
  144.  
  145.   static int open_audio_device (void);
  146. #ifdef Solaris
  147.   static void get_device_type (int fd, audio_device *);
  148. #else
  149.   static int get_device_type (int fd);
  150. #endif
  151.  
  152. public:
  153. #ifdef ULAW
  154.     SparcObuffer (Header *, bool use_speaker, bool use_headphone, bool use_line_out);
  155. #else
  156.     SparcObuffer (uint32 number_of_channels, Header *,
  157.                bool use_speaker, bool use_headphone, bool use_line_out);
  158. #endif
  159.        ~SparcObuffer (void);
  160.   void    append (uint32 channel, int16 value);
  161.   void    write_buffer (int dummy);
  162.  
  163. #ifdef ULAW
  164.   static bool class_suitable (uint32 number_of_channels, bool force_amd);
  165.     // returnvalue == False: no u-law output possible (class unsuitable)
  166. #else
  167.   static bool class_suitable (void);
  168.     // returnvalue == False: no 16-bit output possible (class unsuitable)
  169. #endif
  170. };
  171. #endif    // SPARC
  172.  
  173.  
  174. #ifdef LINUX
  175. class LinuxObuffer : public Obuffer
  176. {
  177.   int16  buffer[OBUFFERSIZE];
  178.   int16 *bufferp[MAXCHANNELS];
  179.   uint32 channels;
  180.   static int audio_fd;
  181.  
  182.   static int open_audio_device (void);
  183.  
  184. public:
  185.     LinuxObuffer (uint32 number_of_channels, Header *);
  186.        ~LinuxObuffer (void);
  187.   void    append (uint32 channel, int16 value);
  188.   void    write_buffer (int dummy);
  189.  
  190.   static bool class_suitable (uint32 number_of_channels);
  191. };
  192. #endif    // LINUX
  193.  
  194. #endif
  195.